package myreactor;

import java.util.Random;

public class ReactorManger {

	private static int POOL_SIZE = 2;
	private static MyReactor mainReactor;
	private static MyReactor[] subReactors = new MyReactor[POOL_SIZE];
	private static Random random = new Random();
	public static void main(String[] args) {
		//初始化mainreactor
		mainReactor = new MyReactor();
		//初始化acceptor
		new AcceptorHandler(mainReactor.getSelector(),8080);
		//启动mainReactor
		mainReactor.start("MainReactor");
		
		//初始化并且启动subReactor
		for(int i = 0;i<POOL_SIZE;i++) {
			subReactors[i] = new MyReactor();
			subReactors[i].start("SubReactor_"+ i);
		}
	}
	
	//获取一个reactor
	public static MyReactor disPatchReactor() {
		return subReactors[random.nextInt(subReactors.length)];
	}
	
	
}
